const http = require('http')

http.createServer(function (req, resp) {
    resp.writeHead(200, {
        'Content-Type': 'text/event-stream',
        'Cache-Control': 'no-cache',
        'Connection': 'keep-alive'
    })
    let interval
    function loop () {
        resp.write(`data:${ new Date().toLocaleString() }\n\n`)
        interval = setTimeout(loop, 2000)
    }
    loop();
    req.on('close', function(){
        clearTimeout(interval)
    })
}).listen(56789)